package service.impl;

import entity.*;
import net.chopinlite.SimpleDate;
import service.IOrderService;

import java.util.*;

public class OrderServiceImpl extends BaseServiceImpl implements IOrderService {
    @Override
    public Order create(User customer, Map<Product, Integer> shoppingcar) {
        Order order = new Order();

        order.setOrderTime(new SimpleDate());//下单时间为当前时间
        order.setCustomer(customer);
        Set<OrderItem> items = new HashSet<>();

        //TODO 从购物车中循环获取键值对，作为订单项目，添加到订单项目集合items中
        for (Map.Entry<Product, Integer> enty : shoppingcar.entrySet()) {
            OrderItem orderitem = new OrderItem();
            Product key = enty.getKey();
            Integer value = enty.getValue();
            orderitem.setProduct(key);
            orderitem.setCount(value);
            items.add(orderitem);
        }
        order.setItems(items);

        return order;
    }
}
